home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
program
/
rcs5ap1s.lzh
/
RCSEDIT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-30
|
24KB
|
883 lines
/*
* RCS stream editor
*/
/**********************************************************************************
* edits the input file according to a
* script from stdin, generated by diff -n
* performs keyword expansion
**********************************************************************************
*/
/* Copyright (C) 1982, 1988, 1989 Walter Tichy
Copyright 1990 by Paul Eggert
Distributed under license by the Free Software Foundation, Inc.
This file is part of RCS.
RCS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
RCS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RCS; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
Report problems and direct all questions to:
rcs-bugs@cs.purdue.edu
*/
/* $Log: rcsedit.c,v $
* Revision 5.8 1991/01/30 14:21:32 apratt
* CI with RCS version 5
*
* Revision 5.7 91/01/29 17:45:46 apratt
* Added AKP_BUGFIXES around my bug fixes
*
* Revision 5.6 91/01/16 15:44:50 apratt
* This version works passably on the ST.
*
* Revision 5.5 90/12/30 05:07:35 eggert
* checked in with -k by apratt at 91.01.10.13.15.10.
*
* Revision 5.5 1990/12/30 05:07:35 eggert
* Fix report of busy RCS files when !defined(O_CREAT) | !defined(O_EXCL).
*
* Revision 5.4 1990/11/01 05:03:40 eggert
* Permit arbitrary data in comment leaders.
*
* Revision 5.3 1990/09/11 02:41:13 eggert
* Tune expandline().
*
* Revision 5.2 1990/09/04 08:02:21 eggert
* Count RCS lines better. Improve incomplete line handling.
*
* Revision 5.1 1990/08/29 07:13:56 eggert
* Add -kkvl.
* Fix bug when getting revisions to files ending in incomplete lines.
* Fix bug in comment leader expansion.
*
* Revision 5.0 1990/08/22 08:12:47 eggert
* Don't require final newline.
* Don't append "checked in with -k by " to logs,
* so that checking in a program with -k doesn't change it.
* Don't generate trailing white space for empty comment leader.
* Remove compile-time limits; use malloc instead. Add -k, -V.
* Permit dates past 1999/12/31. Make lock and temp files faster and safer.
* Ansify and Posixate. Check diff's output.
*
* Revision 4.8 89/05/01 15:12:35 narten
* changed copyright header to reflect current distribution rules
*
* Revision 4.7 88/11/08 13:54:14 narten
* misplaced semicolon caused infinite loop
*
* Revision 4.6 88/08/09 19:12:45 eggert
* Shrink stdio code size; allow cc -R.
*
* Revision 4.5 87/12/18 11:38:46 narten
* Changes from the 43. version. Don't know the significance of the
* first change involving "rewind". Also, additional "lint" cleanup.
* (Guy Harris)
*
* Revision 4.4 87/10/18 10:32:21 narten
* Updating version numbers. Changes relative to version 1.1 actually
* relative to 4.1
*
* Revision 1.4 87/09/24 13:59:29 narten
* Sources now pass through lint (if you ignore printf/sprintf/fprintf
* warnings)
*
* Revision 1.3 87/09/15 16:39:39 shepler
* added an initializatin of the variables editline and linecorr
* this will be done each time a file is processed.
* (there was an obscure bug where if co was used to retrieve multiple files
* it would dump)
* fix attributed to Roy Morris @FileNet Corp ...!felix!roy
*
* Revision 1.2 87/03/27 14:22:17 jenkins
* Port to suns
*
* Revision 4.1 83/05/12 13:10:30 wft
* Added new markers Id and RCSfile; added locker to Header and Id.
* Overhauled expandline completely() (problem with $01234567890123456789@).
* Moved trymatch() and marker table to rcskeys.c.
*
* Revision 3.7 83/05/12 13:04:39 wft
* Added retry to expandline to resume after failed match which ended in $.
* Fixed truncation problem for $19chars followed by@@.
* Log no longer expands full path of RCS file.
*
* Revision 3.6 83/05/11 16:06:30 wft
* added retry to expandline to resume after failed match which ended in $.
* Fixed truncation problem for $19chars followed by@@.
*
* Revision 3.5 82/12/04 13:20:56 wft
* Added expansion of keyword Locker.
*
* Revision 3.4 82/12/03 12:26:54 wft
* Added line number correction in case editing does not start at the
* beginning of the file.
* Changed keyword expansion to always print a space before closing KDELIM;
* Expansion for Header shortened.
*
* Revision 3.3 82/11/14 14:49:30 wft
* removed Suffix from keyword expansion. Replaced fclose with ffclose.
* keyreplace() gets log message from delta, not from curlogmsg.
* fixed expression overflow in while(c=putc(GETC....
* checked nil printing.
*
* Revision 3.2 82/10/18 21:13:39 wft
* I added checks for write errors during the co process, and renamed
* expandstring() to xpandstring().
*
* Revision 3.1 82/10/13 15:52:55 wft
* changed type of result of getc() from char to int.
* made keyword expansion loop in expandline() portable to machines
* without sign-extension.
*/
#include "rcsbase.h"
libId(editId, "$Id: rcsedit.c,v 5.8 1991/01/30 14:21:32 apratt Exp $")
static void keyreplace P((enum markers,const struct hshentry*,FILE*));
FILE *fcopy; /* result file descriptor */
const char *resultfile; /* result file name */
int locker_expansion; /* should the locker name be appended to Id val? */
static FILE *fedit; /* edit file descriptor */
static const char *editfile; /* edit file */
static const char *editdir; /* edit directory */
static unsigned long editline; /*fedit line counter; is always #lines+1 */
static long linecorr; /* #adds - #deletes in each edit run. */
/*used to correct editline in case file is not rewound after */
/* applying one delta */
#define DIRTEMPNAMES 3
enum maker {notmade, real, effective};
struct buf dirtfname[DIRTEMPNAMES]; /* unlink these when done */
static volatile enum maker dirtfmaker[DIRTEMPNAMES]; /* if these are set */
FILE *
initeditfiles(dir)
const char *dir;
/* Function: Initializes resultfile and editfile with temporary filenames
* in directory dir. Opens resultfile for reading and writing, with fcopy
* as file descriptor. fedit is set to nil.
*/
{
editline = 0; /* make sure we start from the beginning*/
linecorr = 0;
editdir = dir;
resultfile = makedirtemp(dir,1);
editfile = nil;
fedit=nil;
errno = 0;
return fcopy = fopen(resultfile,"w+");
}
void
inittmpeditfiles()
{
if (!initeditfiles(tmp()))
efaterror(resultfile);
}
void
arewind(f)
FILE *f;
{
if (fseek(f, (long)0, SEEK_SET) == EOF)
IOerror();
}
void
swapeditfiles(tostdout)
int tostdout;
/* Function: swaps resultfile and editfile, assigns fedit=fcopy,
* rewinds fedit for reading, and opens resultfile for reading and
* writing, using fcopy. If tostdout, fcopy is set to stdout.
*/
{
const char *tmpptr;
fedit=fcopy;
arewind(fedit);
editline = 1; linecorr=0;
tmpptr=editfile; editfile=resultfile; resultfile=tmpptr;
if (tostdout)
fcopy=stdout;
else {
if (!resultfile)
resultfile = makedirtemp(editdir,2);
errno = 0;
if (!(fcopy = fopen(resultfile,"w+")))
efaterror(resultfile);
}
}
void
finishedit(delta)
const struct hshentry *delta;
/* copy the rest of the edit file and close it (if it exists).
* if delta!=nil, perform keyword substitution at the same time.
*/
{
register FILE *fe, *fc;
fe = fedit;
if (fe) {
fc = fcopy;